<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="30%"
    >
      <el-form-item label="是否强制删除虚拟机">
        <el-switch
          v-model="dataForm.force"
          active-color="#ff4949"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>
      <el-form-item label="是否停止虚拟机">
        <el-switch
          v-model="dataForm.stop"
          active-color="#ff4949"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        ids: [],
        isAdd: 1,
        dataForm: {
          force: 0,
          stop: 0,
        },
      };
    },
    methods: {
      init(ids) {
        this.ids = ids;
        this.visible = true;
        this.$refs["dataForm"].resetFields();
      },
      // 表单提交
      dataFormSubmit() {
        this.$http({
          url: this.$http.adornEndogenousUrl("/uservmtrustedrel/delete"),
          method: "post",
          data: this.$http.adornData({
            idents: this.ids,
            force: this.dataForm.force,
            stop: this.dataForm.stop
          }, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.visible = false;
                this.$emit("refreshDataList");
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      }
    }
  };
</script>
